{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "dd40971c",
   "metadata": {},
   "source": [
    "# 第 3 章 矩阵的运算\n",
    "\n",
    "由于矩阵的重要意义和应用, 我们这一章丰富我们的矩阵计算技巧.\n",
    "\n",
    "## 矩阵的加减法, 数乘, 乘法和转置\n",
    "\n",
    "矩阵的矩阵的加减法就是对应矩阵元素的加减法. 因此能完成的前提是参与运算的两个矩阵必须有相同的行列数. 我们可以将**向量**看作特殊的矩阵, 因此向量的加减法也就比照矩阵加减法. 此外, 我们也可以将矩阵的每一行都看作是一个行向量, 或者将矩阵的每一列都看作是列向量. 一般情况下, 我们讨论向量时, 默认其为列向量. \n",
    "\n",
    "这里要注意矩阵的数乘, 它会数乘每一个矩阵元素. 从而导致行列式出现指数 $n$. \n",
    "\n",
    "提示: 矩阵的加减法和数乘, 在线性方程组的背景下, 其意义何在? 我们要培养自己的抽象思维能力, 比如 $n$ 阶向量和矩阵最终将使我们掌握 $n$ 维空间的推理和运算能力. 但是除非我们要做一个只研究形式逻辑的纯粹数学家, 否则我们始终不要彻底脱离我们的问题背景, 也就是所谓的具体和直观. 直观不一定对, 但确实是我们的灵感的来源和应用的归宿. 如果脱离了直观, 我们终将迷失在符号计算的海洋中. 但是如果没有过硬的计算能力, 我们同样缺少渡过这片海洋的能力. 直观背景和逻辑计算, 这两种能力, 我们都需要掌握.\n",
    "\n",
    "下面的程序提供了二维向量在加法和数乘下的几何直观意义."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0c0e9a98",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt\n",
    "import mpl_toolkits.axisartist as axisart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "567b4140",
   "metadata": {},
   "outputs": [],
   "source": [
    "def vec_add(a, b):\n",
    "    n = len(a)\n",
    "    c = np.zeros(n)\n",
    "    for i in range(n):\n",
    "        c[i] = a[i] + b[i]\n",
    "    return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "92eb0d2d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_add(a, b):\n",
    "    c = vec_add(a, b)\n",
    "    plt.plot([0, a[0]], [0, a[1]], 'b-')\n",
    "    plt.plot([0, b[0]], [0, b[1]], 'b-')\n",
    "    plt.plot([0, c[0]], [0, c[1]], 'b-')\n",
    "    plt.plot([a[0], c[0]], [a[1], c[1]], 'b--')\n",
    "    plt.plot([b[0], c[0]], [b[1], c[1]], 'b--')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a41cf013",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAArkklEQVR4nO3deZyNZf8H8M+VtUJkLUtKJVMhpiIUM9Wjnranfd882UollWhRVKSUhDShnvZCQpGYMWQdYydZGksy9n0bs1y/Pz7O78wwzJlx7nPf55zP+/Wa13CfceY6mM9cc93X9f0aay1ERMS7TnF7ACIicmIKahERj1NQi4h4nIJaRMTjFNQiIh5X3IknrVSpkq1du7YTTy0iEpHmzZu3zVpbOb/HHAnq2rVrIzU11YmnFhGJSMaYdcd7TEsfIiIep6AWEfE4BbWIiMcpqEVEPE5BLSLicQHt+jDGrAWwF0A2gCxrbayTgxIREb/CbM9rZa3d5thIREQkX47soxYRiSb//AMMGQKcdhrQrVvwnz/QoLYAfjPGWACfWGsTjv4AY0xbAG0BoFatWsEboYiIB23YAPTuDUyaBKxaxWtnnw08/TRw+unB/VyB3kxsZq1tBOAGAE8aY64++gOstQnW2lhrbWzlyvmeghQRCUv79gETJgDPPw989x2vlSgBfP458Pff/P399wPLlwc/pIEAg9pau/HI+y0ARgO4IvhDERHxll69gObNgQ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eAEoAzuWXjpCLiHicTiaKiHicglpExOMU1CIiHqegFhHxOAW1iIjHKahFRDxOQS0i4nH/B/uDuKmF6l5bAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = np.array([1, 2])\n",
    "b = np.array([0, 3])\n",
    "plot_add(a, b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1d6c1b2",
   "metadata": {},
   "source": [
    "我们可以看到, 我们定义的\"新\"加法, 和平行四边形法则是一致的(事实上, 我们没有必要重新编写加法的函数, 因为 Python 中的向量加法就是这样定义的, 所以再次强调, 我们的程序是为了理解, 而不是实际计算. 作为实际计算, 它们是愚蠢的. ). 而数乘的意义对向量而言也是明确的:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f394ce21",
   "metadata": {},
   "outputs": [],
   "source": [
    "def vec_scalar_prod(alpha, a):\n",
    "    n = len(a)\n",
    "    b = np.zeros(n)\n",
    "    for i in range(n):\n",
    "        b[i] = alpha * a[i]\n",
    "    return b    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "637d18aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_scalar_prod(alpha, a):\n",
    "    b = vec_scalar_prod(alpha, a)\n",
    "    plt.plot([0, a[0]], [0, a[1]], 'b-')\n",
    "    plt.plot([0, b[0]], [0, b[1]], 'b--')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3b521828",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAZJElEQVR4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kFtYhIzMUxqIdGXUAEdM3pV2jXC7rmrIndHLWIiHxdHEfUIiKyDQW1iEjMRRLUZnaqmc03swVmdlMV75uZDa58/19mdnQUdWZTBtd8opl9ZmZvV/76fRR1ZpOZPWpmK8xsznbeT+N9ru6aU3WfzewAM5tsZvPM7N9mdk0Vn0nVfc7wmrN7n0MIef2Ft0pdCBwE1AX+CbT+xmc6AhPx02XaAdPzXWcE13wiMD7qWrN83ScARwNztvN+qu5zhtecqvsMNAOOrvx6T+DdAvj3nMk1Z/U+RzGi/s9huSGETcCWw3K31RV4Mrg3gCIza5bvQrMok2tOnRDCVGD1Dj6StvucyTWnSghhWQhhduXX64B5fPtM1VTd5wyvOauiCOpMDsvN6EDdBMn0eo4zs3+a2UQz+35+SotU2u5zplJ5n82sBGgDTP/GW6m9zzu4Zsjifc7o4IAsy+Sw3IwO1E2QTK5nNr7Xf72ZdQTGAofkurCIpe0+ZyKV99nMGgLPANeGENZ+8+0q/kri73M115zV+xzFiDqTw3LTdqButdcTQlgbQlhf+fUEoI6ZNc5fiZFI232uVhrvs5nVwQNrZAjh2So+krr7XN01Z/s+RxHUmRyW+zxwQeXT4nbAZyGEZfkuNIuqvWYza2pmVvl1W/zerMp7pfmVtvtcrbTd58prGQ7MCyHct52Ppeo+Z3LN2b7PeZ/6CNs5LNfMLqt8fwh+PmNHYAFQDvTMd53ZlOE1nwlcbmabgS+A7qHy8XFSmdko/Ol3YzNbDPQF6kA67zNkdM1pu8/tgfOB/zOztytfuwVoAam9z5lcc1bvs7aQi4jEnHYmiojEnIJaRCTmFNQiIjGnoBYRiTkFtYhIzCmoRURiTkEtIhJz/w9NQB0aR3Q+OQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_scalar_prod(2.5, a)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a4262e7",
   "metadata": {},
   "source": [
    "矩阵乘法的定义要注意行列的匹配. 同时这种乘法也可以自然地作用于行向量乘以矩阵, 矩阵乘以列向量, 行向量乘以列向量, 列向量乘以行向量.\n",
    "\n",
    "提示: 行向量乘以列向量, 列向量乘以行向量, 分别得到什么?\n",
    "\n",
    "下面用程序的形式明确矩阵乘法的规则."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8502c389",
   "metadata": {},
   "outputs": [],
   "source": [
    "def mat_prod(A, B):\n",
    "    m = len(A)\n",
    "    n = len(B[0])\n",
    "    s = len(A[0])\n",
    "    C = np.zeros([m, n])\n",
    "    for i in range(m):\n",
    "        for j in range(n):\n",
    "            for k in range(s):\n",
    "                C[i, j] += A[i, k] * B[k, j]\n",
    "    return C"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b1b01b89",
   "metadata": {},
   "source": [
    "演示一下例 3:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "42cf841f",
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.array([[1, -1], [-1, 1]])\n",
    "B = np.array([[1, 1], [-1, -1]])\n",
    "C = np.array([[2, 0], [0, -2]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4c17fe51",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2.,  2.],\n",
       "       [-2., -2.]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mat_prod(A, B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "71ca28bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2.,  2.],\n",
       "       [-2., -2.]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mat_prod(A, C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "5a5dc3b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0.],\n",
       "       [0., 0.]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mat_prod(B, A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "66c06c20",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=np.array([[1,2],[3,4]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3a8ec9de",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=np.array([[5,6],[7,8]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "4910502e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[19, 22],\n",
       "       [43, 50]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(A,B)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ef51015",
   "metadata": {},
   "source": [
    "显然, 矩阵乘法没有交换律.\n",
    "\n",
    "例 4 是一个常见的形式. 我们经常这样从概念上描述一个线性方程组. \n",
    "\n",
    "例 5 则要深刻的多. 它涉及一个我们在后续章节中才讨论的内容: 线性变换. 我们这里简单介绍一下.\n",
    "\n",
    "考虑在二维的如下图变换, 从左到右:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2c8fedd4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.6, 2, '$y_2$')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAO8AAACICAYAAAAPgbxbAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaC0lEQVR4nO2deXxOV/7HPydPIkhsxSD22AXTJ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mKKTL6vQEgBmxU+ZqIVBvjKoTYAeBHAO2EEBlCCBOLBCtGLwB/BtCv6P08L4SwsJK2bVGNq0gikViGmnpeiURiAVJ5JRKNIpVXItEoUnklEo0ilVci0ShSeSUSjSKVVyLRKFJ5JRKN8v83VZgry+SllwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x144 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize = (4, 2))\n",
    "ax = axisart.Subplot(fig, 111)\n",
    "fig.add_axes(ax)\n",
    "ax.axis[:].set_visible(False)\n",
    "ax.axis[\"x\"] = ax.new_floating_axis(0, 0, axis_direction = \"bottom\")\n",
    "ax.axis[\"y\"] = ax.new_floating_axis(1, 0, axis_direction = \"bottom\")\n",
    "ax.axis[\"x\"].set_axisline_style(\"->\", size = 1.0)\n",
    "ax.axis[\"y\"].set_axisline_style(\"->\", size = 1.0)\n",
    "ax.annotate(text= 'x', xy = (2.5, 0), xytext = (2.5, 0.1))\n",
    "ax.annotate(text= 'y', xy = (0, 2.5), xytext = (-0.5, 2.5))\n",
    "plt.xlim(-2.6, 2.6)\n",
    "plt.ylim(-0.1, 2.6)\n",
    "plt.plot([-1, -1, -2, -1], [1, 2, 1, 1], 'b-')\n",
    "plt.plot([1, 1, 2, 1], [1, 2, 1, 1], 'r-')\n",
    "plt.plot([0, -1], [0, 1], 'b--')\n",
    "ax.annotate(\"\", xy = (-1, 1), xytext = (-0.9, 0.9), \n",
    "            arrowprops = dict(arrowstyle = \"->\", color = \"b\"))\n",
    "ax.annotate(text= r\"$x_1$\", xy = (-1, 1), xytext = (-0.9, 1))\n",
    "plt.plot([0, -1], [0, 2], 'b--')\n",
    "ax.annotate(\"\", xy = (-1, 2), xytext = (-0.9, 1.8), \n",
    "            arrowprops = dict(arrowstyle = \"->\", color = \"b\"))\n",
    "ax.annotate(text= r\"$x_2$\", xy = (-1, 2), xytext = (-0.9, 2))\n",
    "plt.plot([0, 1], [0, 1], 'r--')\n",
    "ax.annotate(\"\", xy = (1, 1), xytext = (0.9, 0.9), \n",
    "            arrowprops = dict(arrowstyle = \"->\", color = \"r\"))\n",
    "ax.annotate(text= r\"$y_1$\", xy = (1, 1), xytext = (0.6, 1))\n",
    "plt.plot([0, 1], [0, 2], 'r--')\n",
    "ax.annotate(\"\", xy = (1, 2), xytext = (0.9, 1.8), \n",
    "            arrowprops = dict(arrowstyle = \"->\", color = \"r\"))\n",
    "ax.annotate(text= r\"$y_2$\", xy = (1, 2), xytext = (0.6, 2))"
   ]
  },
  {
   "cell_type": "raw",
   "id": "2bc87921",
   "metadata": {},
   "source": [
    "考虑从蓝到红的图形的变换, 这是一个关于 $y$ 轴的轴对称变换. 那么它能否用矩阵向量乘法来表示呢? 也就是说, 是否存在 $2$ 阶方阵 \n",
    "$$\n",
    "A = \\left(\\begin{array}{cc}\n",
    "a_{11} & a_{12} \\\\\n",
    "a_{21} & a_{22}\n",
    "\\end{array}\\right),\n",
    "$$\n",
    "使得\n",
    "$$\n",
    "y = Ax\n",
    "$$\n",
    "就是这个变换. 这里 $x$ 和 $y$ 分别是变换前和变换后的向量. 我们从图上看到, 如果真的存在这样可以用矩阵乘法的线性变换, 那么它必须满足:\n",
    "$$\n",
    "\\begin{array}{rcl}\n",
    "y_1 &=& A x_1\\\\\n",
    "y_2 &=& A x_2\n",
    "\\end{array}\n",
    "$$\n",
    "由此解得:\n",
    "$$\n",
    "A = \\left(\\begin{array}{cc}\n",
    "-1 & 0 \\\\\n",
    "0 & 1\n",
    "\\end{array}\\right)\n",
    "$$\n",
    "不难验证, 一切 $2$ 维平面上的关于 $y$ 轴的轴对称变换, 都可以用\n",
    "$$\n",
    "y = A x\n",
    "$$\n",
    "表示. 实际上, 我们就把这种可以用矩阵乘法表示的变换, 称为**线性变换**. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40e4228f",
   "metadata": {},
   "source": [
    "现在我们再看例 5, 就有了不同的意义. 既然矩阵向量乘法表达了线性变换, 那么矩阵矩阵乘法表达的是什么? 矩阵乘矩阵仍然是矩阵. 所以结果也是一个新的线性变换. 进一步, 例 5 告诉我们: 如果\n",
    "$$\n",
    "x = A y,\n",
    "$$\n",
    "且\n",
    "$$\n",
    "y = B z,\n",
    "$$\n",
    "那么有\n",
    "$$\n",
    "x = A y = A (B z) = (A B) z.\n",
    "$$\n",
    "即矩阵乘法代表了复合线性变换. 或者说, 矩阵乘法满足结合律. (这里我们已经在抽象层面上, 触碰到了结合律的本质. 进一步的讨论需要更专业的代数知识.)\n",
    "\n",
    "提示: 请举一例, $AB = 0$, 但 $A$ 和 $B$ 均不为零矩阵."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4061d94",
   "metadata": {},
   "source": [
    "例 6 展示了对角阵的乘法作用. 它和标准矩阵乘法不矛盾. 请明确**对角矩阵**, **数量矩阵**和**单位矩阵**的定义, 区别和记号表示(再次强调符号的重要性, 看不懂符号, 你不可能理解相关内容, 比如什么是矩阵 $A$ 的 **$k$ 次幂**). \n",
    "\n",
    "提示: 始终要注意, 矩阵乘法没有交换律, 因此左乘和右乘是完全不同的两个运算.\n",
    "\n",
    "定理 1 的证明, 展示了一种新的矩阵和行列式证明技巧, 值得参考.\n",
    "\n",
    "提示: 在例 7 的启示下, 讨论矩阵方程的求解技巧. \n",
    "\n",
    "矩阵的转置是一个重要运算. 它可以推广到向量, 行列向量通过转置运算互相转换."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "743dd5b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=np.array([[1,2,3],[4,5,6],[7,8,8]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "038c0f8f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.999999999999999"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linalg.det(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "cdfa673e",
   "metadata": {},
   "outputs": [],
   "source": [
    "A_abs=np.linalg.det(np.round(A))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "93a20035",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.999999999999999"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A_abs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ca2cf489",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=np.linalg.inv(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8848a9e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-2.66666667,  2.66666667, -1.        ],\n",
       "       [ 3.33333333, -4.33333333,  2.        ],\n",
       "       [-1.        ,  2.        , -1.        ]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "2e1225b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ -8.,   8.,  -3.],\n",
       "       [ 10., -13.,   6.],\n",
       "       [ -3.,   6.,  -3.]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B*A_abs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "470d3f20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1*5*8+2*6*7+4*8*3-3*5*7-2*4*8-1*8*6\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72eb644f",
   "metadata": {},
   "source": [
    "## 初等矩阵\n",
    "\n",
    "对单位阵，做初等变换，就得到对应的初等矩阵。对矩阵的行初等变换，等价于左乘以初等矩阵；对矩阵做列初等变换，等价于右乘以初等矩阵。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57c7569e",
   "metadata": {},
   "source": [
    "交换单位阵的两行(列)，得到第一型初等矩阵。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6aee71f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "E = np.eye(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f723800d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., 0., 0.],\n",
       "       [0., 0., 0., 1., 0.],\n",
       "       [0., 0., 1., 0., 0.],\n",
       "       [0., 1., 0., 0., 0.],\n",
       "       [0., 0., 0., 0., 1.]])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "E13 = np.array(E)\n",
    "E13[1,:] = E[3,:]\n",
    "E13[3,:] = E[1,:]\n",
    "E13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0fe6b8de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.24843639, 0.2003024 , 0.31014779, 0.12931653, 0.82292452],\n",
       "       [0.31996334, 0.96297463, 0.90259353, 0.99288699, 0.30842949],\n",
       "       [0.7823278 , 0.49696971, 0.10341871, 0.14541087, 0.73672285],\n",
       "       [0.45734773, 0.61695136, 0.34920722, 0.50870593, 0.54404269],\n",
       "       [0.08226004, 0.9517814 , 0.6520713 , 0.20646285, 0.44240927]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.random.rand(5, 5)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "95df3df2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.24843639, 0.2003024 , 0.31014779, 0.12931653, 0.82292452],\n",
       "       [0.45734773, 0.61695136, 0.34920722, 0.50870593, 0.54404269],\n",
       "       [0.7823278 , 0.49696971, 0.10341871, 0.14541087, 0.73672285],\n",
       "       [0.31996334, 0.96297463, 0.90259353, 0.99288699, 0.30842949],\n",
       "       [0.08226004, 0.9517814 , 0.6520713 , 0.20646285, 0.44240927]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(E13, A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "b80b956e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.24843639, 0.12931653, 0.31014779, 0.2003024 , 0.82292452],\n",
       "       [0.31996334, 0.99288699, 0.90259353, 0.96297463, 0.30842949],\n",
       "       [0.7823278 , 0.14541087, 0.10341871, 0.49696971, 0.73672285],\n",
       "       [0.45734773, 0.50870593, 0.34920722, 0.61695136, 0.54404269],\n",
       "       [0.08226004, 0.20646285, 0.6520713 , 0.9517814 , 0.44240927]])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(A, E13)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79005de6",
   "metadata": {},
   "source": [
    "单位阵的某一行(列)乘以常数 $c$, 为第二型初等矩阵。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "72892bc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., 0., 0.],\n",
       "       [0., 1., 0., 0., 0.],\n",
       "       [0., 0., 3., 0., 0.],\n",
       "       [0., 0., 0., 1., 0.],\n",
       "       [0., 0., 0., 0., 1.]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "E = np.eye(5)\n",
    "E3 = np.array(E)\n",
    "E3[2,:] = 3 * E[2,:]\n",
    "E3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "dc86a729",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.46972945, 0.46284674, 0.31011129, 0.7329915 , 0.33980783],\n",
       "       [0.85411152, 0.46554677, 0.85403363, 0.49213825, 0.66812769],\n",
       "       [0.90897649, 0.48512581, 0.23137257, 0.49465098, 0.5880362 ],\n",
       "       [0.63850683, 0.62919688, 0.4582229 , 0.97065002, 0.19132891],\n",
       "       [0.29295666, 0.15904801, 0.9907355 , 0.98130433, 0.55428717]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.random.rand(5, 5)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5e9929ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.46972945, 0.46284674, 0.31011129, 0.7329915 , 0.33980783],\n",
       "       [0.85411152, 0.46554677, 0.85403363, 0.49213825, 0.66812769],\n",
       "       [2.72692946, 1.45537743, 0.6941177 , 1.48395293, 1.76410859],\n",
       "       [0.63850683, 0.62919688, 0.4582229 , 0.97065002, 0.19132891],\n",
       "       [0.29295666, 0.15904801, 0.9907355 , 0.98130433, 0.55428717]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(E3, A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "324d3c6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.46972945, 0.46284674, 0.93033386, 0.7329915 , 0.33980783],\n",
       "       [0.85411152, 0.46554677, 2.5621009 , 0.49213825, 0.66812769],\n",
       "       [0.90897649, 0.48512581, 0.6941177 , 0.49465098, 0.5880362 ],\n",
       "       [0.63850683, 0.62919688, 1.37466869, 0.97065002, 0.19132891],\n",
       "       [0.29295666, 0.15904801, 2.9722065 , 0.98130433, 0.55428717]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(A,E3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31c13e14",
   "metadata": {},
   "source": [
    "单位阵的某一行(列)乘以常数  𝑐 , 加到另一行(列)，为第三型初等矩阵。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "eaeba82a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 0., 0., 0., 0.],\n",
       "       [0., 1., 0., 0., 0.],\n",
       "       [0., 0., 1., 0., 0.],\n",
       "       [0., 0., 2., 1., 0.],\n",
       "       [0., 0., 0., 0., 1.]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "E = np.eye(5)\n",
    "C2E3 = np.array(E)\n",
    "C2E3[3,:] = E[3,:] + 2 * E[2,:]\n",
    "C2E3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "0dc542b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.22185326, 0.73624331, 0.12391866, 0.26228155, 0.79861155],\n",
       "       [0.21546352, 0.54394636, 0.65551623, 0.43115759, 0.31536734],\n",
       "       [0.62145931, 0.19878944, 0.22284703, 0.56335265, 0.45922891],\n",
       "       [0.89102052, 0.56703514, 0.22646205, 0.30080271, 0.51564593],\n",
       "       [0.4092224 , 0.01477592, 0.71819221, 0.31304265, 0.13651212]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.random.rand(5, 5)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7dd35a7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.22185326, 0.73624331, 0.12391866, 0.26228155, 0.79861155],\n",
       "       [0.21546352, 0.54394636, 0.65551623, 0.43115759, 0.31536734],\n",
       "       [0.62145931, 0.19878944, 0.22284703, 0.56335265, 0.45922891],\n",
       "       [2.13393915, 0.96461403, 0.67215612, 1.42750801, 1.43410374],\n",
       "       [0.4092224 , 0.01477592, 0.71819221, 0.31304265, 0.13651212]])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(C2E3,A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b17f3a32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.22185326, 0.73624331, 0.64848176, 0.26228155, 0.79861155],\n",
       "       [0.21546352, 0.54394636, 1.51783141, 0.43115759, 0.31536734],\n",
       "       [0.62145931, 0.19878944, 1.34955233, 0.56335265, 0.45922891],\n",
       "       [0.89102052, 0.56703514, 0.82806747, 0.30080271, 0.51564593],\n",
       "       [0.4092224 , 0.01477592, 1.34427751, 0.31304265, 0.13651212]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(A, C2E3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "241cfae0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.22185326, 0.73624331, 0.12391866, 0.26228155, 0.79861155],\n",
       "       [0.21546352, 0.54394636, 0.65551623, 0.43115759, 0.31536734],\n",
       "       [0.62145931, 0.19878944, 0.22284703, 0.56335265, 0.45922891],\n",
       "       [0.89102052, 0.56703514, 0.22646205, 0.30080271, 0.51564593],\n",
       "       [0.4092224 , 0.01477592, 0.71819221, 0.31304265, 0.13651212]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "185dccd9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6484817646380114"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A[0,3]*2+A[0,2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4aa5c0d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
